/// 应用常量定义
/// 包含应用配置、UI常量、BLE协议常量等

/// 应用配置常量
class AppConstants {
  static const String appName = 'Calendar Manager';
  static const String appVersion = '1.0.0';
  static const String appDescription = 'ESP32 BLE Calendar Management App';
  
  // 扫描相关常量
  static const int scanTimeoutSeconds = 30;
  static const int scanResultLimit = 100;
  
  // 连接相关常量
  static const int connectionTimeoutSeconds = 10;
  static const int mtuRequestSize = 185;
  
  // 自动同步相关常量
  static const int defaultAutoSyncIntervalSeconds = 60;
  static const int minAutoSyncIntervalSeconds = 10;
  static const int maxAutoSyncIntervalSeconds = 3600;
  
  // 重试机制常量
  static const int maxRetryCount = 3;
  static const int retryDelayMilliseconds = 500;
}

/// BLE协议常量
class BLEConstants {
  // 服务UUID (已更新为日历专用服务UUID)
  static const String targetServiceUuid = '00001849-0000-1000-8000-00805f9b34fb';
  
  // 特征UUID (已更新为日历专用特征UUID)
  static const String dataCharacteristicUuid = '00002a4f-0000-1000-8000-00805f9b34fb';
  static const String commandCharacteristicUuid = '00002a50-0000-1000-8000-00805f9b34fb';
  static const String intervalCharacteristicUuid = '00002a4f-0000-1000-8000-00805f9b34fb';
  
  // 设备名称过滤
  static const String targetDeviceName = 'Calendar';
  
  // 协议帧格式常量
  static const int frameHeaderCmd = 0xAA;
  static const int frameHeaderResp = 0xBB;
  static const int frameTailCmd = 0x55;
  static const int frameTailResp = 0x66;
  
  // 命令类型
  static const int cmdTypeData = 0x01;
  static const int cmdTypeFile = 0x02;
  static const int cmdTypeControl = 0x03;
  static const int cmdTypeTimeSync = 0x04;
  
  // 响应类型
  static const int respTypeAck = 0x01;
  static const int respTypeRetransmit = 0x02;
  static const int respTypeComplete = 0x03;
  static const int respTypeError = 0x04;
  
  // 错误码
  static const int errSuccess = 0;
  static const int errCrcMismatch = 1;
  static const int errFrameFormat = 2;
  static const int errBufferFull = 3;
  static const int errTimeout = 4;
  static const int errPacketLost = 5;
  
  // 数据包大小限制
  static const int maxDataPerPacket = 244;
  static const int maxPackets = 65535;
  
  // CRC多项式
  static const int crcPolynomial = 0x1021; // XMODEM多项式
}

/// UI界面常量
class UIConstants {
  // 颜色常量
  static const int primaryColorValue = 0xFF2196F3;
  static const int secondaryColorValue = 0xFF03A9F4;
  static const int accentColorValue = 0xFF00BCD4;
  static const int successColorValue = 0xFF4CAF50;
  static const int warningColorValue = 0xFFFF9800;
  static const int errorColorValue = 0xFFF44336;
  
  // 尺寸常量
  static const double defaultPadding = 16.0;
  static const double smallPadding = 8.0;
  static const double largePadding = 24.0;
  static const double borderRadius = 8.0;
  static const double buttonHeight = 48.0;
  static const double iconSize = 24.0;
  
  // 动画时长
  static const int shortAnimationDuration = 200;
  static const int mediumAnimationDuration = 300;
  static const int longAnimationDuration = 500;
  
  // 字体大小
  static const double smallFontSize = 12.0;
  static const double mediumFontSize = 14.0;
  static const double largeFontSize = 16.0;
  static const double titleFontSize = 18.0;
  static const double headlineFontSize = 24.0;
}

/// 权限相关常量
class PermissionConstants {
  // 权限请求超时
  static const int permissionRequestTimeoutSeconds = 30;
  
  // 权限描述
  static const String locationPermissionDescription = 
      '需要位置权限来扫描附近的蓝牙设备。蓝牙扫描需要访问位置服务来获取设备信息。';
  
  static const String bluetoothPermissionDescription = 
      '需要蓝牙权限来连接和管理蓝牙设备。';
}

/// 错误消息常量
class ErrorMessages {
  // 连接错误
  static const String connectionFailed = '设备连接失败';
  static const String connectionTimeout = '连接超时';
  static const String deviceNotFound = '未找到目标设备';
  static const String serviceDiscoveryFailed = '服务发现失败';
  static const String characteristicNotFound = '未找到必需的特征';
  
  // 权限错误
  static const String locationPermissionDenied = '位置权限被拒绝，无法扫描蓝牙设备';
  static const String bluetoothPermissionDenied = '蓝牙权限被拒绝，无法使用蓝牙功能';
  static const String bluetoothDisabled = '蓝牙未启用，请启用蓝牙后重试';
  
  // 数据通信错误
  static const String dataSendFailed = '数据发送失败';
  static const String dataReceiveFailed = '数据接收失败';
  static const String crcCheckFailed = '数据校验失败';
  static const String frameFormatError = '数据帧格式错误';
  
  // 通用错误
  static const String unknownError = '发生未知错误';
  static const String networkError = '网络连接错误';
  static const String operationFailed = '操作失败，请重试';
}

/// 成功消息常量
class SuccessMessages {
  static const String connectionSuccess = '设备连接成功';
  static const String dataSendSuccess = '数据发送成功';
  static const String dataReceiveSuccess = '数据接收成功';
  static const String syncComplete = '同步完成';
  static const String operationSuccess = '操作成功';
}

/// 提示消息常量
class InfoMessages {
  static const String scanningDevices = '正在扫描设备...';
  static const String connectingDevice = '正在连接设备...';
  static const String discoveringServices = '正在发现服务...';
  static const String sendingData = '正在发送数据...';
  static const String receivingData = '正在接收数据...';
  static const String autoSyncEnabled = '自动同步已启用';
  static const String autoSyncDisabled = '自动同步已禁用';
}

/// 本地化键值常量
class LocalizationKeys {
  static const String appTitle = 'app_title';
  static const String scanDevices = 'scan_devices';
  static const String connect = 'connect';
  static const String disconnect = 'disconnect';
  static const String sendData = 'send_data';
  static const String syncTime = 'sync_time';
  static const String autoSync = 'auto_sync';
  static const String settings = 'settings';
  static const String about = 'about';
}

/// 路由名称常量
class RouteNames {
  static const String home = '/';
  static const String deviceScanner = '/scanner';
  static const String deviceDetail = '/device';
  static const String settings = '/settings';
  static const String about = '/about';
}

/// 存储键值常量
class StorageKeys {
  static const String deviceList = 'device_list';
  static const String lastConnectedDevice = 'last_connected_device';
  static const String autoSyncEnabled = 'auto_sync_enabled';
  static const String autoSyncInterval = 'auto_sync_interval';
  static const String themeMode = 'theme_mode';
  static const String language = 'language';
}